import { loadRoute3Path } from '@/utils/loadRemote'
import { localStore } from '@/utils/sessionStore'
import axios from 'axios'
import { isEmpty } from 'lodash'
export default {
    data() {
      return {
        envData: null
      }
    },
    created() {
      if (this.belong) this.preEnvRequest(this.belong)
    },
    computed: {
    dispatchProxy() {
       if (Vue.prototype.dispatchProxy) {
            return Vue.prototype.dispatchProxy(this)
        } else {
            return this.dispatch
         }
      },
      isExpress() {
        const globalConfig = localStore.get('globalConfig')
        return _.get(globalConfig, 'isExpress', false)
      },
      preurl() {
        let url = loadRoute3Path('')
        return this.isExpress ? `${url}/` : `${url}/afc/`
      },
      header() {
        return { Authorization: localStore.get('uniqueId') }
      }
    },
    methods: {
      preEnvRequest(belong) {
          const url = `${this.preurl}api/afc/integration/env/list`
          const params = { belong }
          const data = {}
          const headers = this.header
          axios.get(url, { params, data, headers }).then(({ data }) => {
            if (!isEmpty(data)) {
              this.envData = data
            }
          })
      },
      requestVoiceSynth() {
        return new Promise((resolve, reject) => {
          const url = `${this.preurl}api/afc/integration/env/list`
          const params = { belong: this.group }
          const data = {}
          const headers = this.header
          axios.get(url, { params, data, headers }).then(({ data }) => {
            if (!isEmpty(data)) {
               resolve(data)
            }
          })
        })
      },
      getCodeValueByCode(code, data) {
        console.log('------环境变量---->:', this.envData)
        const envArr = this.envData ? this.envData : !isEmpty(data) ? data : []
        const envItem = envArr.find((el) => el.code === code)
        return envItem ? envItem.codeValue : null
      }
    }
}